import { makeObservable, action, observable } from 'mobx'

export default class ToDoStore {
  constructor () {
    makeObservable(this, {
      list: observable,
      getList: action
    })
  }

  // todolist走mobx状态管理
  // todolist的数据操作都是通过状态管理
  list = []
  getList (payload) {
    switch (payload.type) {
      case 'add':
        this.list.push(payload.doning)
        break
      case 'edit':
        this.list.map((item, index, list) => {
          if (item.id === payload.doning.id) {
            list[index].task = payload.doning.task
          }
        })
        break
      case 'remove':
        this.list = this.list.filter(item => item.id !== payload.doning.id)
        break
      default:
        alert('其他操作无效')
        break
    }
  }

}